package project2.ui.manage;

import project2.config.Config;
import project2.util.FileUtil;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
 * 帮助窗口
 */
public class HelpDialog extends JFrame {
    private static final long serialVersionUID = 1L;

    public HelpDialog() {
        // 配置窗口基本信息
        this.setTitle("帮助");
        this.setIconImage(new ImageIcon(Config.LOGO_IMG).getImage());
        this.setSize(Config.HELP_DIALOG_WIDTH, Config.HELP_DIALOG_HEIGHT);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        JTextPane helpContentTextPane = new JTextPane();// 文本面板
        helpContentTextPane.setEditable(false);
        helpContentTextPane.setContentType("text/html;charset=utf-8");// 以网页的形式显示
        try {
            helpContentTextPane.setText(FileUtil.readFileToString(Config.HELP_FILE_PATH));
        } catch (IOException e) {
            e.printStackTrace();
        }

        JScrollPane scrollPane = new JScrollPane(helpContentTextPane);// 文本面板外面套一层滚动面板
        scrollPane.setAutoscrolls(true);

        this.add(scrollPane, BorderLayout.CENTER);// 滚动面板放入到窗口中
    }

}